jQuery(document).ready(function ($) {
  "use strict";

  var wow = new WOW({
    boxClass: 'wow',
    animateClass: 'animated',
    offset: 0,
    mobile: false,
    live: true,
    scrollContainer: null
  });

  wow.init();

  /*-------------------------------------
       Sidebar Toggle
    -------------------------------------*/
  $('.share-toggle-btn').on('click', function(e) {
    $(this).closest(".share-toggle-wrap").toggleClass("open-share");
  });

  /*-------------------------------------
   Masonry
   -------------------------------------*/
  $('.masonry-items').masonry({
    // set itemSelector so .grid-sizer is not used in layout
    itemSelector: '.masonry-item',
    // use element for option
    columnWidth: '.masonry-item',
    /*percentPosition: true*/
    /*horizontalOrder: true*/
  });

  /*---------------------------------------
  Background Parallax
  --------------------------------------- */
  if ($('.parallaxie').length) {
    $(".parallaxie").parallaxie({
      speed: 0.5,
      offset: 0,
    });
  }

  $('.sticky-coloum-wrap .sticky-coloum-item').theiaStickySidebar({
    additionalMarginTop: 145
  });


  /*---------------------------------------
  Transparent Navbar or Header
  --------------------------------------- */
  var transparentNavbar = $("header.transparent-navbar"),
    navbarH = transparentNavbar.outerHeight() || 0,
    transparentHeader = $("header.transparent-header"),
    headerH = transparentHeader.outerHeight() || 0;

  if (transparentNavbar.length) {
    transparentNavbar.css('margin-bottom', -navbarH);
  }

  if (transparentHeader.length) {
    transparentHeader.css('margin-bottom', -headerH);
  }

  /*-------------------------------------
   Select2 activation code
   -------------------------------------*/
  if ($('select.select2').length) {
    $('select.select2').select2({
      theme: 'classic',
      dropdownAutoWidth: true,
      width: '100%'
    });
    $('.filter-search select.select2').select2({
      theme: 'classic',
      width: '100%'
    });
  }

  /*--------------------------------------
  Isotope initialization
  --------------------------------------*/
  var $container = $(".isotope-wrap");
  if ($container.length > 0) {
    var $isotope;
    var blogGallerIso = $(".featuredContainer", $container).imagesLoaded(function() {
      var selectero = $container.find('.isotope-classes-tab .nav-item:first-child').data('filter') || '*';

      $isotope = $(".featuredContainer", $container).isotope({
        filter: selectero,
        transitionDuration: "1s",
        hiddenStyle: {
          opacity: 0,
          transform: "scale(0.001)"
        },
        visibleStyle: {
          transform: "scale(1)",
          opacity: 1
        }
      });
    });
    $container.find(".isotope-classes-tab").on("click", "a", function() {
      var $this = $(this);
      $this
        .parent(".isotope-classes-tab")
        .find("a")
        .removeClass("current");
      $this.addClass("current");
      var selector = $this.attr("data-filter");
      $isotope.isotope({
        filter: selector
      });
      return false;
    });
  }

  /*-------------------------------------
  Section background image
  -------------------------------------*/
  $("[data-bg-image]").each(function() {
    var img = $(this).data("bg-image");
    $(this).css({
      backgroundImage: "url(" + img + ")"
    });
  });


  $('[data-type="section-switch"], #dropdown > ul > li > a').on('click', function() {
    if (location.pathname.replace(/^\//, '') == this.pathname.replace(/^\//, '') && location.hostname == this.hostname) {
      var target = $(this.hash);
      if (target.length > 0) {

        target = target.length ? target : $('[name=' + this.hash.slice(1) + ']');
        $('html,body').animate({
          scrollTop: target.offset().top
        }, 1000);
        return false;
      }
    }
  });

  /*-------------------------------------
  On Scroll
  -------------------------------------*/
  $(window).on('scroll', function() {

    // Back Top Button
    if ($(window).scrollTop() > 700) {
      $('.return-to-top').addClass('back-top');
    } else {
      $('.return-to-top').removeClass('back-top');
    }

    // Sticky Menu
    if ($('header').hasClass('sticky-fixed-after')) {
      var stickyPlaceHolder = $("#sticky-placeholder"),
        menu = $("#navbar-wrap"),
        menuH = menu.outerHeight(),
        topbarH = $('#topbar-wrap').outerHeight() || 0,
        targrtScroll = topbarH,
        header = $("header");
      if ($(window).scrollTop() > targrtScroll) {
        header.addClass('sticky');
        stickyPlaceHolder.height(menuH);
      } else {
        header.removeClass('sticky');
        stickyPlaceHolder.height(0);
      }
    }
  });

  /*-------------------------------------
  Jquery Serch Box
  -------------------------------------*/
  $('a[href="#template-search"]').on("click", function(event) {
    event.preventDefault();
    var target = $("#template-search");
    target.addClass("open");
    setTimeout(function() {
      target.find('input').focus();
    }, 600);
    return false;
  });

  $("#template-search, #template-search button.close").on("click keyup", function(event) {
    if (
      event.target === this ||
      event.target.className === "close" ||
      event.keyCode === 27
    ) {
      $(this).removeClass("open");
    }
  });

  /*-------------------------------------
  After Load All Content Add a Class In Body
  -------------------------------------*/
  $(window).on('load', addNewClass);

  function addNewClass() {
    $('body').imagesLoaded().done(function(instance) {
      $('body').addClass('loaded');
    });
  }

  /*-------------------------------------
  Intersection Observer
  -------------------------------------*/
  if (!!window.IntersectionObserver) {
    let observer = new IntersectionObserver((entries, observer) => {
      entries.forEach(entry => {
        if (entry.isIntersecting) {
          entry.target.classList.add("active-animation");
          //entry.target.src = entry.target.dataset.src;
          observer.unobserve(entry.target);
        }
      });
    }, {
      rootMargin: "0px 0px -100px 0px"
    });
    document.querySelectorAll('.has-animation').forEach(block => {
      observer.observe(block)
    });
  } else {
    document.querySelectorAll('.has-animation').forEach(block => {
      block.classList.remove('has-animation')
    });
  }

});


function aeen_content_load_scripts(){

  /*-------------------------------------
    Carousel slider initiation
    -------------------------------------*/
    if ($.fn.owlCarousel) {

      function createCarousel(carousel) {

        var loop = carousel.data('loop'),
          rtl = carousel.data('rtl'),
          items = carousel.data('items'),
          margin = carousel.data('margin'),
          stagePadding = carousel.data('stage-padding'),
          autoplay = carousel.data('autoplay'),
          autoplayTimeout = carousel.data('autoplay-timeout'),
          smartSpeed = carousel.data('smart-speed'),
          dots = carousel.data('dots'),
          nav = carousel.data('nav'),
          navSpeed = carousel.data('nav-speed'),
          rXsmall = carousel.data('r-x-small'),
          rXsmallNav = carousel.data('r-x-small-nav'),
          rXsmallDots = carousel.data('r-x-small-dots'),
          rXmedium = carousel.data('r-x-medium'),
          rXmediumNav = carousel.data('r-x-medium-nav'),
          rXmediumDots = carousel.data('r-x-medium-dots'),
          rSmall = carousel.data('r-small'),
          rSmallNav = carousel.data('r-small-nav'),
          rSmallDots = carousel.data('r-small-dots'),
          rMedium = carousel.data('r-medium'),
          rMediumNav = carousel.data('r-medium-nav'),
          rMediumDots = carousel.data('r-medium-dots'),
          rLarge = carousel.data('r-large'),
          rLargeNav = carousel.data('r-large-nav'),
          rLargeDots = carousel.data('r-large-dots'),
          rExtraLarge = carousel.data('r-extra-large'),
          rExtraLargeNav = carousel.data('r-extra-large-nav'),
          rExtraLargeDots = carousel.data('r-extra-large-dots'),
          center = carousel.data('center'),
          custom_nav = carousel.data('custom-nav') || '';
        carousel.addClass('owl-carousel');
        var owl = carousel.owlCarousel({
          loop: (loop ? true : false),
          rtl: (rtl ? false : true),
          items: (items ? items : 4),
          lazyLoad: true,
          margin: (margin ? margin : 0),
          autoplay: (autoplay ? true : false),
          autoplayTimeout: (autoplayTimeout ? autoplayTimeout : 1000),
          smartSpeed: (smartSpeed ? smartSpeed : 250),
          dots: (dots ? true : false),
          nav: (nav ? true : false),
          navText: ['<i class="fas fa-chevron-left"></i>', '<i class="fas fa-chevron-right"></i>'],
          navSpeed: (navSpeed ? true : false),
          center: (center ? true : false),
          responsiveClass: true,
          responsive: {
            0: {
              items: (rXsmall ? rXsmall : 1),
              nav: (rXsmallNav ? true : false),
              dots: (rXsmallDots ? true : false)
            },
            576: {
              items: (rXmedium ? rXmedium : 2),
              nav: (rXmediumNav ? true : false),
              dots: (rXmediumDots ? true : false)
            },
            768: {
              items: (rSmall ? rSmall : 3),
              nav: (rSmallNav ? true : false),
              dots: (rSmallDots ? true : false)
            },
            992: {
              items: (rMedium ? rMedium : 4),
              nav: (rMediumNav ? true : false),
              dots: (rMediumDots ? true : false)
            },
            1200: {
              items: (rLarge ? rLarge : 5),
              nav: (rLargeNav ? true : false),
              dots: (rLargeDots ? true : false)
            },
            1400: {
              items: (rExtraLarge ? rExtraLarge : 6),
              nav: (rExtraLargeNav ? true : false),
              dots: (rExtraLargeDots ? true : false)
            }
          }
        });
        if (custom_nav) {
          var nav = $(custom_nav),
            nav_next = $('.rt-next', nav),
            nav_prev = $('.rt-prev', nav);

          nav_next.on('click', function(e) {
            e.preventDefault();
            owl.trigger('next.owl.carousel');
            return false;
          });

          nav_prev.on('click', function(e) {
            e.preventDefault();
            owl.trigger('prev.owl.carousel');
            return false;
          });
        }

      }

      $('.rc-carousel').each(function() {
        var carousel = $(this),
          options = $.extend({
            trigger_start: '',
            trigger_end: '',
          }, carousel.data('options'));


        if (!options.trigger_start && !options.trigger_end) {
          createCarousel(carousel);

        } else {
          var tempOwl = '';
          $(window).on('resize load', function() {
            var wW = $(window).width();

            if (wW <= options.trigger_start) {
              createCarousel(carousel);
              console.log('called', 'create')
            } else {
              carousel.owlCarousel('destroy').removeClass('owl-carousel');
            }

          });
        }
      });
    }

    $(".practice-active").owlCarousel({
      rtl:true,
      loop: true,
      autoplay: false,
      smartSpeed: 1500,
      autoplayHoverPause: true,
      margin: 0,
      autoplayTimeout: 6000,
      nav: false,
      dots: false,
      responsive: {
        0: {
          items: 1,
        },
        768: {
          items: 1,
        },
        992: {
          items: 2,
        },
        1000: {
          items: 3,
        },
      },
    });

    // Slick carousel
    if ($.fn.slick) {
      $('.slick-carousel').each(function() {
        let $carousel = $(this);
        $carousel.imagesLoaded(function() {
          var data = $carousel.data('slick'),
            slidesToShowTab = data.slidesToShowTab,
            slidesToShowMobile = data.slidesToShowMobile,
            slidesToShowMobiles = data.slidesToShowMobiles;
          $carousel.slick({
            centerPadding: '0px',
            responsive: [{
                breakpoint: 992,
                settings: {
                  slidesToShow: slidesToShowTab,
                  slidesToScroll: slidesToShowTab
                }
              },
              {
                breakpoint: 768,
                settings: {
                  slidesToShow: slidesToShowMobile,
                  slidesToScroll: slidesToShowMobile
                }
              },
              {
                breakpoint: 576,
                settings: {
                  slidesToShow: slidesToShowMobiles,
                  slidesToScroll: slidesToShowMobiles
                }
              }
            ]
          });
        });
      });

    }

    // Testimonial Active
    $('.testimonial-active').slick({
      dots: false,
      arrows: true,
      infinite: true,
      speed: 300,
      prevArrow: '<button type="button" class="pinik-prev"><i class="fas fa-angle-left"></i></button>',
      nextArrow: '<button type="button" class="pinik-next"><i class="fas fa-angle-right"></i></button>',
      slidesToShow: 3,
      slidesToScroll: 1,
      responsive: [
        {
          breakpoint: 1024,
          settings: {
            slidesToShow: 2,
            slidesToScroll: 1,
            infinite: true,
            arrows: false,
          }
        },
        {
          breakpoint: 991,
          settings: {
            slidesToShow: 2,
            slidesToScroll: 1
          }
        },
        {
          breakpoint: 480,
          settings: {
            slidesToShow: 1,
            slidesToScroll: 1,
            arrows: false,
          }
        }
      ]
    });

    /*-------------------------------------
    Mobile Menu
    -------------------------------------*/
    var a = $('.offscreen-navigation .menu');

    if (a.length) {
        $(".menu-item-has-children").append("<span></span>");
        $(".page_item_has_children").append("<span></span>");

        a.children("li").addClass("menu-item-parent");

        $('.menu-item-has-children > span').on('click', function () {
            $(this).siblings('a').first().toggleClass('opened');
            var _self = $(this),
                sub_menu = _self.parent().find('>.sub-menu');
            if (_self.hasClass('open')) {
                sub_menu.slideUp();
                _self.removeClass('open');
            } else {
                sub_menu.slideDown();
                _self.addClass('open');
            }
        });
        $('.page_item_has_children > span').on('click', function () {
            var _self = $(this),
                sub_menu = _self.parent().find('>.children');
            if (_self.hasClass('open')) {
                sub_menu.slideUp();
                _self.removeClass('open');
            } else {
                sub_menu.slideDown();
                _self.addClass('open');
            }
        });

        $('.offscreen-navigation .menu-item-parent > a, .offscreen-navigation .menu-item-has-children a').on('click', function () {
            setTimeout(function() {
                $('.mean-bar .sidebarBtn').trigger('click');
            }, 300)
        });
    }

    $('.mean-bar .sidebarBtn').on('click', function (e) {
      e.preventDefault();
      if ($('.rt-slide-nav').is(":visible")) {
        $('.rt-slide-nav').slideUp();
        $('body').removeClass('slidemenuon');
      } else {
        $('.rt-slide-nav').slideDown();
        $('body').addClass('slidemenuon');
      }

    });

    /*-------------------------------------
    Count Up
    -------------------------------------*/
    var counterContainer = $('.counter');
    if (counterContainer.length) {
      counterContainer.counterUp({
        delay: 50,
        time: 5000
      });
    }
}


(function ($) {
    "use strict";

      /*-------------------------------------
   Auto height for product listing
   -------------------------------------*/
  $(window).on('load resize', function() {

    equalHeight();

    // Gallery Popup
    if ($('.zoom-gallery').length) {
      $('.zoom-gallery').each(function() {
        $(this).magnificPopup({
          delegate: 'a.popup-zoom',
          type: 'image',
          gallery: {
            enabled: true
          }
        });
      });
    }

    // Elementor Frontend Load
      $(window).on('elementor/frontend/init', function () {
          if (elementorFrontend.isEditMode()) {
              elementorFrontend.hooks.addAction('frontend/element_ready/widget', function () {
                  aeen_content_load_scripts();
              });
          }
      });

      // Equal Height
        function equalHeight() {
          var imgH = 0,
            boxH = 0,
            wWidth = $(window).width(),
            allH;
          $('.equal-height-wrap .item-figure,.equal-height-wrap .item-content').height('auto');
          if (wWidth > 767) {
            $('.equal-height-wrap').each(function() {
              var self = $(this);
              var TempImgH = self.find('.item-figure').height();
              imgH = TempImgH > imgH ? TempImgH : imgH;
              var TempBoxH = self.find('.item-content').outerHeight();
              boxH = TempBoxH > boxH ? TempBoxH : boxH;
            });
            allH = imgH;
            allH = boxH > imgH ? boxH : imgH;
            $('.equal-height-wrap .item-figure,.equal-height-wrap .item-content').height(allH + "px");
          }
        }

    // Popup
    var yPopup = $(".popup-youtube");
    if (yPopup.length) {
      yPopup.magnificPopup({
        disableOn: 700,
        type: 'iframe',
        mainClass: 'mfp-fade',
        removalDelay: 160,
        preloader: false,
        fixedContentPos: false
      });
    }
  });


  // Window Load
    $(window).on('load', function () {
        aeen_content_load_scripts();
    });

})(jQuery);